﻿#region Using directives

using System;
using System.Data;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using VCS.Entities;
using VCS.Data;

#endregion

namespace VCS.Data.Bases
{	
	///<summary>
	/// This class is the base class for any <see cref="AppointmentDoctorProviderBase"/> implementation.
	/// It exposes CRUD methods as well as selecting on index, foreign keys and custom stored procedures.
	///</summary>
	public abstract class AppointmentDoctorProviderBaseCore : EntityViewProviderBase<AppointmentDoctor>
	{
		#region Custom Methods
		
		
		#endregion

		#region Helper Functions
		
		/*
		///<summary>
		/// Fill an VList&lt;AppointmentDoctor&gt; From a DataSet
		///</summary>
		/// <param name="dataSet">the DataSet</param>
		/// <param name="rows">The collection to fill</param>
		/// <param name="start">Start row</param>
		/// <param name="pagelen">number of row.</param>
		///<returns><see chref="VList&lt;AppointmentDoctor&gt;"/></returns>
		protected static VList&lt;AppointmentDoctor&gt; Fill(DataSet dataSet, VList<AppointmentDoctor> rows, int start, int pagelen)
		{
			if (dataSet.Tables.Count == 1)
			{
				return Fill(dataSet.Tables[0], rows, start, pagelen);
			}
			else
			{
				return new VList<AppointmentDoctor>();
			}	
		}
		
		
		///<summary>
		/// Fill an VList&lt;AppointmentDoctor&gt; From a DataTable
		///</summary>
		/// <param name="dataTable">the DataTable that hold the data.</param>
		/// <param name="rows">The collection to fill</param>
		/// <param name="start">Start row</param>
		/// <param name="pagelen">number of row.</param>
		///<returns><see chref="VList<AppointmentDoctor>"/></returns>
		protected static VList&lt;AppointmentDoctor&gt; Fill(DataTable dataTable, VList<AppointmentDoctor> rows, int start, int pagelen)
		{
			int recordnum = 0;
			
			System.Collections.IEnumerator dataRows =  dataTable.Rows.GetEnumerator();
			
			while (dataRows.MoveNext() && (pagelen != 0))
			{
				if(recordnum >= start)
				{
					DataRow row = (DataRow)dataRows.Current;
				
					AppointmentDoctor c = new AppointmentDoctor();
					c.Username = (Convert.IsDBNull(row["Username"]))?string.Empty:(System.String)row["Username"];
					c.Password = (Convert.IsDBNull(row["Password"]))?string.Empty:(System.String)row["Password"];
					c.Title = (Convert.IsDBNull(row["Title"]))?string.Empty:(System.String)row["Title"];
					c.Firstname = (Convert.IsDBNull(row["Firstname"]))?string.Empty:(System.String)row["Firstname"];
					c.Lastname = (Convert.IsDBNull(row["Lastname"]))?string.Empty:(System.String)row["Lastname"];
					c.DisplayName = (Convert.IsDBNull(row["DisplayName"]))?string.Empty:(System.String)row["DisplayName"];
					c.CellPhone = (Convert.IsDBNull(row["CellPhone"]))?string.Empty:(System.String)row["CellPhone"];
					c.Email = (Convert.IsDBNull(row["Email"]))?string.Empty:(System.String)row["Email"];
					c.Avatar = (Convert.IsDBNull(row["Avatar"]))?string.Empty:(System.String)row["Avatar"];
					c.Note = (Convert.IsDBNull(row["Note"]))?string.Empty:(System.String)row["Note"];
					c.UserGroupId = (Convert.IsDBNull(row["UserGroupId"]))?string.Empty:(System.String)row["UserGroupId"];
					c.ServicesId = (Convert.IsDBNull(row["ServicesId"]))?(int)0:(System.Int32?)row["ServicesId"];
					c.IsFemale = (Convert.IsDBNull(row["IsFemale"]))?false:(System.Boolean)row["IsFemale"];
					c.IsDisabled = (Convert.IsDBNull(row["IsDisabled"]))?false:(System.Boolean)row["IsDisabled"];
					c.CreateUser = (Convert.IsDBNull(row["CreateUser"]))?string.Empty:(System.String)row["CreateUser"];
					c.CreateDate = (Convert.IsDBNull(row["CreateDate"]))?DateTime.MinValue:(System.DateTime)row["CreateDate"];
					c.UpdateUser = (Convert.IsDBNull(row["UpdateUser"]))?string.Empty:(System.String)row["UpdateUser"];
					c.UpdateDate = (Convert.IsDBNull(row["UpdateDate"]))?DateTime.MinValue:(System.DateTime)row["UpdateDate"];
					c.AcceptChanges();
					rows.Add(c);
					pagelen -= 1;
				}
				recordnum += 1;
			}
			return rows;
		}
		*/	
						
		///<summary>
		/// Fill an <see cref="VList&lt;AppointmentDoctor&gt;"/> From a DataReader.
		///</summary>
		/// <param name="reader">Datareader</param>
		/// <param name="rows">The collection to fill</param>
		/// <param name="start">Start row</param>
		/// <param name="pageLength">number of row.</param>
		///<returns>a <see cref="VList&lt;AppointmentDoctor&gt;"/></returns>
		protected VList<AppointmentDoctor> Fill(IDataReader reader, VList<AppointmentDoctor> rows, int start, int pageLength)
		{
			int recordnum = 0;
			while (reader.Read() && (pageLength != 0))
			{
				if(recordnum >= start)
				{
					AppointmentDoctor entity = null;
					if (DataRepository.Provider.UseEntityFactory)
					{
						entity = EntityManager.CreateViewEntity<AppointmentDoctor>("AppointmentDoctor",  DataRepository.Provider.EntityCreationalFactoryType); 
					}
					else
					{
						entity = new AppointmentDoctor();
					}
					
					entity.SuppressEntityEvents = true;

					entity.Username = (System.String)reader[((int)AppointmentDoctorColumn.Username)];
					//entity.Username = (Convert.IsDBNull(reader["Username"]))?string.Empty:(System.String)reader["Username"];
					entity.Password = (reader.IsDBNull(((int)AppointmentDoctorColumn.Password)))?null:(System.String)reader[((int)AppointmentDoctorColumn.Password)];
					//entity.Password = (Convert.IsDBNull(reader["Password"]))?string.Empty:(System.String)reader["Password"];
					entity.Title = (reader.IsDBNull(((int)AppointmentDoctorColumn.Title)))?null:(System.String)reader[((int)AppointmentDoctorColumn.Title)];
					//entity.Title = (Convert.IsDBNull(reader["Title"]))?string.Empty:(System.String)reader["Title"];
					entity.Firstname = (reader.IsDBNull(((int)AppointmentDoctorColumn.Firstname)))?null:(System.String)reader[((int)AppointmentDoctorColumn.Firstname)];
					//entity.Firstname = (Convert.IsDBNull(reader["Firstname"]))?string.Empty:(System.String)reader["Firstname"];
					entity.Lastname = (reader.IsDBNull(((int)AppointmentDoctorColumn.Lastname)))?null:(System.String)reader[((int)AppointmentDoctorColumn.Lastname)];
					//entity.Lastname = (Convert.IsDBNull(reader["Lastname"]))?string.Empty:(System.String)reader["Lastname"];
					entity.DisplayName = (System.String)reader[((int)AppointmentDoctorColumn.DisplayName)];
					//entity.DisplayName = (Convert.IsDBNull(reader["DisplayName"]))?string.Empty:(System.String)reader["DisplayName"];
					entity.CellPhone = (reader.IsDBNull(((int)AppointmentDoctorColumn.CellPhone)))?null:(System.String)reader[((int)AppointmentDoctorColumn.CellPhone)];
					//entity.CellPhone = (Convert.IsDBNull(reader["CellPhone"]))?string.Empty:(System.String)reader["CellPhone"];
					entity.Email = (reader.IsDBNull(((int)AppointmentDoctorColumn.Email)))?null:(System.String)reader[((int)AppointmentDoctorColumn.Email)];
					//entity.Email = (Convert.IsDBNull(reader["Email"]))?string.Empty:(System.String)reader["Email"];
					entity.Avatar = (reader.IsDBNull(((int)AppointmentDoctorColumn.Avatar)))?null:(System.String)reader[((int)AppointmentDoctorColumn.Avatar)];
					//entity.Avatar = (Convert.IsDBNull(reader["Avatar"]))?string.Empty:(System.String)reader["Avatar"];
					entity.Note = (reader.IsDBNull(((int)AppointmentDoctorColumn.Note)))?null:(System.String)reader[((int)AppointmentDoctorColumn.Note)];
					//entity.Note = (Convert.IsDBNull(reader["Note"]))?string.Empty:(System.String)reader["Note"];
					entity.UserGroupId = (System.String)reader[((int)AppointmentDoctorColumn.UserGroupId)];
					//entity.UserGroupId = (Convert.IsDBNull(reader["UserGroupId"]))?string.Empty:(System.String)reader["UserGroupId"];
					entity.ServicesId = (reader.IsDBNull(((int)AppointmentDoctorColumn.ServicesId)))?null:(System.Int32?)reader[((int)AppointmentDoctorColumn.ServicesId)];
					//entity.ServicesId = (Convert.IsDBNull(reader["ServicesId"]))?(int)0:(System.Int32?)reader["ServicesId"];
					entity.IsFemale = (System.Boolean)reader[((int)AppointmentDoctorColumn.IsFemale)];
					//entity.IsFemale = (Convert.IsDBNull(reader["IsFemale"]))?false:(System.Boolean)reader["IsFemale"];
					entity.IsDisabled = (System.Boolean)reader[((int)AppointmentDoctorColumn.IsDisabled)];
					//entity.IsDisabled = (Convert.IsDBNull(reader["IsDisabled"]))?false:(System.Boolean)reader["IsDisabled"];
					entity.CreateUser = (reader.IsDBNull(((int)AppointmentDoctorColumn.CreateUser)))?null:(System.String)reader[((int)AppointmentDoctorColumn.CreateUser)];
					//entity.CreateUser = (Convert.IsDBNull(reader["CreateUser"]))?string.Empty:(System.String)reader["CreateUser"];
					entity.CreateDate = (System.DateTime)reader[((int)AppointmentDoctorColumn.CreateDate)];
					//entity.CreateDate = (Convert.IsDBNull(reader["CreateDate"]))?DateTime.MinValue:(System.DateTime)reader["CreateDate"];
					entity.UpdateUser = (reader.IsDBNull(((int)AppointmentDoctorColumn.UpdateUser)))?null:(System.String)reader[((int)AppointmentDoctorColumn.UpdateUser)];
					//entity.UpdateUser = (Convert.IsDBNull(reader["UpdateUser"]))?string.Empty:(System.String)reader["UpdateUser"];
					entity.UpdateDate = (System.DateTime)reader[((int)AppointmentDoctorColumn.UpdateDate)];
					//entity.UpdateDate = (Convert.IsDBNull(reader["UpdateDate"]))?DateTime.MinValue:(System.DateTime)reader["UpdateDate"];
					entity.AcceptChanges();
					entity.SuppressEntityEvents = false;
					
					rows.Add(entity);
					pageLength -= 1;
				}
				recordnum += 1;
			}
			return rows;
		}
		
		
		/// <summary>
		/// Refreshes the <see cref="AppointmentDoctor"/> object from the <see cref="IDataReader"/>.
		/// </summary>
		/// <param name="reader">The <see cref="IDataReader"/> to read from.</param>
		/// <param name="entity">The <see cref="AppointmentDoctor"/> object to refresh.</param>
		protected void RefreshEntity(IDataReader reader, AppointmentDoctor entity)
		{
			reader.Read();
			entity.Username = (System.String)reader[((int)AppointmentDoctorColumn.Username)];
			//entity.Username = (Convert.IsDBNull(reader["Username"]))?string.Empty:(System.String)reader["Username"];
			entity.Password = (reader.IsDBNull(((int)AppointmentDoctorColumn.Password)))?null:(System.String)reader[((int)AppointmentDoctorColumn.Password)];
			//entity.Password = (Convert.IsDBNull(reader["Password"]))?string.Empty:(System.String)reader["Password"];
			entity.Title = (reader.IsDBNull(((int)AppointmentDoctorColumn.Title)))?null:(System.String)reader[((int)AppointmentDoctorColumn.Title)];
			//entity.Title = (Convert.IsDBNull(reader["Title"]))?string.Empty:(System.String)reader["Title"];
			entity.Firstname = (reader.IsDBNull(((int)AppointmentDoctorColumn.Firstname)))?null:(System.String)reader[((int)AppointmentDoctorColumn.Firstname)];
			//entity.Firstname = (Convert.IsDBNull(reader["Firstname"]))?string.Empty:(System.String)reader["Firstname"];
			entity.Lastname = (reader.IsDBNull(((int)AppointmentDoctorColumn.Lastname)))?null:(System.String)reader[((int)AppointmentDoctorColumn.Lastname)];
			//entity.Lastname = (Convert.IsDBNull(reader["Lastname"]))?string.Empty:(System.String)reader["Lastname"];
			entity.DisplayName = (System.String)reader[((int)AppointmentDoctorColumn.DisplayName)];
			//entity.DisplayName = (Convert.IsDBNull(reader["DisplayName"]))?string.Empty:(System.String)reader["DisplayName"];
			entity.CellPhone = (reader.IsDBNull(((int)AppointmentDoctorColumn.CellPhone)))?null:(System.String)reader[((int)AppointmentDoctorColumn.CellPhone)];
			//entity.CellPhone = (Convert.IsDBNull(reader["CellPhone"]))?string.Empty:(System.String)reader["CellPhone"];
			entity.Email = (reader.IsDBNull(((int)AppointmentDoctorColumn.Email)))?null:(System.String)reader[((int)AppointmentDoctorColumn.Email)];
			//entity.Email = (Convert.IsDBNull(reader["Email"]))?string.Empty:(System.String)reader["Email"];
			entity.Avatar = (reader.IsDBNull(((int)AppointmentDoctorColumn.Avatar)))?null:(System.String)reader[((int)AppointmentDoctorColumn.Avatar)];
			//entity.Avatar = (Convert.IsDBNull(reader["Avatar"]))?string.Empty:(System.String)reader["Avatar"];
			entity.Note = (reader.IsDBNull(((int)AppointmentDoctorColumn.Note)))?null:(System.String)reader[((int)AppointmentDoctorColumn.Note)];
			//entity.Note = (Convert.IsDBNull(reader["Note"]))?string.Empty:(System.String)reader["Note"];
			entity.UserGroupId = (System.String)reader[((int)AppointmentDoctorColumn.UserGroupId)];
			//entity.UserGroupId = (Convert.IsDBNull(reader["UserGroupId"]))?string.Empty:(System.String)reader["UserGroupId"];
			entity.ServicesId = (reader.IsDBNull(((int)AppointmentDoctorColumn.ServicesId)))?null:(System.Int32?)reader[((int)AppointmentDoctorColumn.ServicesId)];
			//entity.ServicesId = (Convert.IsDBNull(reader["ServicesId"]))?(int)0:(System.Int32?)reader["ServicesId"];
			entity.IsFemale = (System.Boolean)reader[((int)AppointmentDoctorColumn.IsFemale)];
			//entity.IsFemale = (Convert.IsDBNull(reader["IsFemale"]))?false:(System.Boolean)reader["IsFemale"];
			entity.IsDisabled = (System.Boolean)reader[((int)AppointmentDoctorColumn.IsDisabled)];
			//entity.IsDisabled = (Convert.IsDBNull(reader["IsDisabled"]))?false:(System.Boolean)reader["IsDisabled"];
			entity.CreateUser = (reader.IsDBNull(((int)AppointmentDoctorColumn.CreateUser)))?null:(System.String)reader[((int)AppointmentDoctorColumn.CreateUser)];
			//entity.CreateUser = (Convert.IsDBNull(reader["CreateUser"]))?string.Empty:(System.String)reader["CreateUser"];
			entity.CreateDate = (System.DateTime)reader[((int)AppointmentDoctorColumn.CreateDate)];
			//entity.CreateDate = (Convert.IsDBNull(reader["CreateDate"]))?DateTime.MinValue:(System.DateTime)reader["CreateDate"];
			entity.UpdateUser = (reader.IsDBNull(((int)AppointmentDoctorColumn.UpdateUser)))?null:(System.String)reader[((int)AppointmentDoctorColumn.UpdateUser)];
			//entity.UpdateUser = (Convert.IsDBNull(reader["UpdateUser"]))?string.Empty:(System.String)reader["UpdateUser"];
			entity.UpdateDate = (System.DateTime)reader[((int)AppointmentDoctorColumn.UpdateDate)];
			//entity.UpdateDate = (Convert.IsDBNull(reader["UpdateDate"]))?DateTime.MinValue:(System.DateTime)reader["UpdateDate"];
			reader.Close();
	
			entity.AcceptChanges();
		}
		
		/*
		/// <summary>
		/// Refreshes the <see cref="AppointmentDoctor"/> object from the <see cref="DataSet"/>.
		/// </summary>
		/// <param name="dataSet">The <see cref="DataSet"/> to read from.</param>
		/// <param name="entity">The <see cref="AppointmentDoctor"/> object.</param>
		protected static void RefreshEntity(DataSet dataSet, AppointmentDoctor entity)
		{
			DataRow dataRow = dataSet.Tables[0].Rows[0];
			
			entity.Username = (Convert.IsDBNull(dataRow["Username"]))?string.Empty:(System.String)dataRow["Username"];
			entity.Password = (Convert.IsDBNull(dataRow["Password"]))?string.Empty:(System.String)dataRow["Password"];
			entity.Title = (Convert.IsDBNull(dataRow["Title"]))?string.Empty:(System.String)dataRow["Title"];
			entity.Firstname = (Convert.IsDBNull(dataRow["Firstname"]))?string.Empty:(System.String)dataRow["Firstname"];
			entity.Lastname = (Convert.IsDBNull(dataRow["Lastname"]))?string.Empty:(System.String)dataRow["Lastname"];
			entity.DisplayName = (Convert.IsDBNull(dataRow["DisplayName"]))?string.Empty:(System.String)dataRow["DisplayName"];
			entity.CellPhone = (Convert.IsDBNull(dataRow["CellPhone"]))?string.Empty:(System.String)dataRow["CellPhone"];
			entity.Email = (Convert.IsDBNull(dataRow["Email"]))?string.Empty:(System.String)dataRow["Email"];
			entity.Avatar = (Convert.IsDBNull(dataRow["Avatar"]))?string.Empty:(System.String)dataRow["Avatar"];
			entity.Note = (Convert.IsDBNull(dataRow["Note"]))?string.Empty:(System.String)dataRow["Note"];
			entity.UserGroupId = (Convert.IsDBNull(dataRow["UserGroupId"]))?string.Empty:(System.String)dataRow["UserGroupId"];
			entity.ServicesId = (Convert.IsDBNull(dataRow["ServicesId"]))?(int)0:(System.Int32?)dataRow["ServicesId"];
			entity.IsFemale = (Convert.IsDBNull(dataRow["IsFemale"]))?false:(System.Boolean)dataRow["IsFemale"];
			entity.IsDisabled = (Convert.IsDBNull(dataRow["IsDisabled"]))?false:(System.Boolean)dataRow["IsDisabled"];
			entity.CreateUser = (Convert.IsDBNull(dataRow["CreateUser"]))?string.Empty:(System.String)dataRow["CreateUser"];
			entity.CreateDate = (Convert.IsDBNull(dataRow["CreateDate"]))?DateTime.MinValue:(System.DateTime)dataRow["CreateDate"];
			entity.UpdateUser = (Convert.IsDBNull(dataRow["UpdateUser"]))?string.Empty:(System.String)dataRow["UpdateUser"];
			entity.UpdateDate = (Convert.IsDBNull(dataRow["UpdateDate"]))?DateTime.MinValue:(System.DateTime)dataRow["UpdateDate"];
			entity.AcceptChanges();
		}
		*/
			
		#endregion Helper Functions
	}//end class

	#region AppointmentDoctorFilterBuilder
	
	/// <summary>
	/// A strongly-typed instance of the <see cref="SqlFilterBuilder&lt;EntityColumn&gt;"/> class
	/// that is used exclusively with a <see cref="AppointmentDoctor"/> object.
	/// </summary>
	[CLSCompliant(true)]
	public class AppointmentDoctorFilterBuilder : SqlFilterBuilder<AppointmentDoctorColumn>
	{
		#region Constructors

		/// <summary>
		/// Initializes a new instance of the AppointmentDoctorFilterBuilder class.
		/// </summary>
		public AppointmentDoctorFilterBuilder() : base() { }

		/// <summary>
		/// Initializes a new instance of the AppointmentDoctorFilterBuilder class.
		/// </summary>
		/// <param name="ignoreCase">Specifies whether to create case-insensitive statements.</param>
		public AppointmentDoctorFilterBuilder(bool ignoreCase) : base(ignoreCase) { }

		/// <summary>
		/// Initializes a new instance of the AppointmentDoctorFilterBuilder class.
		/// </summary>
		/// <param name="ignoreCase">Specifies whether to create case-insensitive statements.</param>
		/// <param name="useAnd">Specifies whether to combine statements using AND or OR.</param>
		public AppointmentDoctorFilterBuilder(bool ignoreCase, bool useAnd) : base(ignoreCase, useAnd) { }

		#endregion Constructors
	}

	#endregion AppointmentDoctorFilterBuilder

	#region AppointmentDoctorParameterBuilder
	
	/// <summary>
	/// A strongly-typed instance of the <see cref="ParameterizedSqlFilterBuilder&lt;EntityColumn&gt;"/> class
	/// that is used exclusively with a <see cref="AppointmentDoctor"/> object.
	/// </summary>
	[CLSCompliant(true)]
	public class AppointmentDoctorParameterBuilder : ParameterizedSqlFilterBuilder<AppointmentDoctorColumn>
	{
		#region Constructors

		/// <summary>
		/// Initializes a new instance of the AppointmentDoctorParameterBuilder class.
		/// </summary>
		public AppointmentDoctorParameterBuilder() : base() { }

		/// <summary>
		/// Initializes a new instance of the AppointmentDoctorParameterBuilder class.
		/// </summary>
		/// <param name="ignoreCase">Specifies whether to create case-insensitive statements.</param>
		public AppointmentDoctorParameterBuilder(bool ignoreCase) : base(ignoreCase) { }

		/// <summary>
		/// Initializes a new instance of the AppointmentDoctorParameterBuilder class.
		/// </summary>
		/// <param name="ignoreCase">Specifies whether to create case-insensitive statements.</param>
		/// <param name="useAnd">Specifies whether to combine statements using AND or OR.</param>
		public AppointmentDoctorParameterBuilder(bool ignoreCase, bool useAnd) : base(ignoreCase, useAnd) { }

		#endregion Constructors
	}

	#endregion AppointmentDoctorParameterBuilder
	
	#region AppointmentDoctorSortBuilder
    
    /// <summary>
    /// A strongly-typed instance of the <see cref="SqlSortBuilder&lt;EntityColumn&gt;"/> class
	/// that is used exclusively with a <see cref="AppointmentDoctor"/> object.
    /// </summary>
    [CLSCompliant(true)]
    public class AppointmentDoctorSortBuilder : SqlSortBuilder<AppointmentDoctorColumn>
    {
		#region Constructors

		/// <summary>
		/// Initializes a new instance of the AppointmentDoctorSqlSortBuilder class.
		/// </summary>
		public AppointmentDoctorSortBuilder() : base() { }

		#endregion Constructors

    }    
    #endregion AppointmentDoctorSortBuilder

} // end namespace
